
require(["../conf/config.js"], function(){
	require(["jquery", "common"], function($,com){
		$(function(){
		 		/* let $sliding =$('#nc_1_n1z');
				 let $slbox =$('#huakuai_big');
				let $sltext=$('.nc-lang-cnt');
				let $bg =$("#bg-yegr"); 
				//console.log($sliding.innerWidth())
				 $sliding.mousedown(function(e){
					 
					let obj = {
					    X : e.offsetX
					}
					console.log($slbox.innerWidth())
					  $(document).mousemove(function(e){
						let $slidingLeft = Math.min(($slbox.innerWidth()- $sliding.innerWidth()), Math.max(0, e.clientX - obj.X - $slbox.innerWidth()))
					
						 $sliding.css({
						 	 left: $slidingLeft + 'px';
						 })
						$bg.css({
							width : $slidingLeft + 'px'
						}) 
					}) 
				}) */
				
			let slbox =document.getElementById('huakuai_big');
			let sliding =document.getElementById("nc_1_n1z");
			let sltext =document.getElementsByClassName("nc-lang-cnt")[0];
			let bg=document.getElementById("bg-yegr")
			//console.log(sliding)
				sliding.addEventListener('mousedown', function(e) {
				    e = e || event
				    let obj = {
				        X : e.offsetX
				    }
				    document.onmousemove = function (e) {
				        e = e || event
				        console.log(slbox.offsetWidth - sliding.offsetWidth)
				        let btnLeft = Math.min((slbox.offsetWidth - sliding.offsetWidth - 2), Math.max(0, e.clientX - obj.X - slbox.offsetLeft))
				        sliding.style.left = btnLeft + 'px'
				        bg.style.width = btnLeft + 'px'
				    }
				})
				
				document.documentElement.addEventListener('mouseup', function () {
				     if (sliding.offsetLeft <= (slbox.offsetWidth - sliding.offsetWidth - 2) *0.98) {
				             drag(sliding, {left : 0})
				             drag(bg, {width : 0})
				         } else {
				             let n = slbox.offsetWidth - sliding.offsetWidth
				             console.log(n)
				             drag(sliding, {left : n}, function () {
				                // bg.style.background = 'orange'
				                 sltext.innerHTML = '验证通过';
								 sltext.style.color ='#fff';
								//sliding.removeEventListener('mousedown',fn)
				             })
				             drag(bg, {width : n})
				         }
				     document.onmousemove = null
				 }) 
				// 封装运动函数
							const drag = function (ele, target, cbk) {
								let obj = {}
								for (let arrt in target) {
									obj[arrt] = setInterval(() => {
										let tarValue = target[arrt]
										let currentValue
										if (arrt === 'opacity') {
											currentValue = (getComputedStyle(ele)[arrt]) * 100
										} else {
											currentValue = parseInt(getComputedStyle(ele)[arrt])
										}
										let speed = (tarValue - currentValue) / 10
										speed = speed > 0 ? Math.ceil(speed) : Math.floor(speed)
										if (arrt === 'opacity') {
											ele.style.opacity = (currentValue + speed) / 100
											if (ele.style.opacity * 100 == tarValue) {
												console.log(speed + 'qwe')
												clearInterval(obj[arrt])
												delete obj[arrt]
												if (isStop(obj) == 0) {
													cbk ? cbk() : ''
												}
											}
										} else {
											ele.style[arrt] = currentValue + speed + 'px'
											if (parseInt(ele.style[arrt]) == tarValue) {
												console.log(speed + 'qwe')
												clearInterval(obj[arrt])
												delete obj[arrt]
												if (isStop(obj) == 0) {
													cbk ? cbk() : ''
												}
											}
										}
									}, 30)
								}
							}
							function isStop(obj) {
								let r = 0
								for (let arrt in obj) {
									r++
								}
								return r
							}
					
							let username = $('#text_1');
							let pwd = $('#pwd');
				username.blur(function() {
								
								if (username.val() == "") {
									$('#hint1').html('辣鸡!不输入账号吗?');
								} else if(/^1[34578]\d{9}$/.test(username.val()) || /^\w[a-z]([a-z0-9]*[-_]?[a-z0-9]+)*@([a-z0-9]*[-_]?[a-z0-9]+)+[\.][a-z]{2,3}([\.][a-z]{2})$/i
				.test(username.val()) ){
									$('#hint1').html('');
								}else{
									$('#hint1').html('辣鸡!你输入的格式有误,请看准要求!');
								}
								
							})
								pwd.blur(function(){
									 if (pwd.val() == "") {
										console.log("aaa")
										$('#hint2').html('辣鸡,不输入密码?');
									}else if( /^(?![^a-zA-Z]+$)(?!\D+$)/.test(pwd.val())){
										console.log("bbb")
										$('#hint2').html('');
									}else{
										console.log("ccc")
										$('#hint2').html('辣鸡,密码格式不对,手速慢点!');
									} 
									
								})
							
							console.log()
							$("#sub").click(function(){
								$.ajax({
									url : "http://localhost:8000/static/jsons/login.json",
									success : function(date){
										//console.log(date);
										let $user =$(date);
										console.log($user)
										 $user.each(function(index,items){
											
											//console.log(items)
											
											if(items.account == username.val() && items.password ==pwd.val() && $("#nc_1_n1z").offset().left !=519.5){
												$("#center_big").hide();
												 $('#hint2').hide();
												$('#hint1').hide(); 
												$(".icon-denglu").html(items.username);
												$(".icon-denglu").toggleClass("");
												let $haha =
															`<marquee loop="-1">温馨提示：近期发现有个叫于二哈的冒充一加官方旗舰店客服人员，进行诈骗。在此提示您，本店不会用任何方式通知您将货款打入指定银行或支付宝账户，也不会用非店铺旺旺联系您，如遇此类情况，请不要轻易上当 !!</marquee>`
															$("#center").append($haha);
															
											}else{
												alert("账号密码错误或这验证未通过!")
											}
												
										}) 
									}
								})
								
								
								
							})
							
						
		})//onload
		
		
	})
})